package com.example.listmoudle.stagger.adapter

import android.view.ViewGroup
import com.android.baselibrary.base.BaseAdapter
import com.bumptech.glide.Glide
import com.example.listmoudle.R
import com.example.listmoudle.bean.NumberBean
import com.example.listmoudle.databinding.ListLayoutItemBinding
import java.util.WeakHashMap

class StaggerListAdapter(val width:Int):BaseAdapter<NumberBean,ListLayoutItemBinding>() {
    private var mMap:WeakHashMap<Int,Double> = WeakHashMap<Int,Double>()
    override fun getItemLayoutId(): Int = R.layout.list_layout_item

    override fun covert(binding: ListLayoutItemBinding, t: NumberBean, position: Int) {
       var height = 0.0
        val params =  binding.tvList.layoutParams as ViewGroup.LayoutParams
        height = if (mMap[position]!=null){
            mMap[position]!!
        }else{
            when (t.n) {
                in 100 until 120 -> width*1.6
                in 120 until 130 ->width*1.5
                in 130 until 140 ->width*1.4
                else ->width*1.3
            }
        }
        params.height = height.toInt()
        params.width = width
        binding.imageList.layoutParams = params
        binding.bean = t

       binding.tvList.setOnClickListener {
           t.n  = t.n+1
       }
        Glide.with(binding.imageList.context).load(t.imageUrl).into(binding.imageList)


    }

}